package com.example.demo;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.junit.jupiter.api.Test;

public class pinyintest {

    @Test
    public void ss() throws BadHanyuPinyinOutputFormatCombination {
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        //拼音小写
        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        //不带声调
        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
        //要转换的中文，格式，转换之后的拼音的分隔符，遇到不能转换的是否保留   wo,shi,zhong,guo,ren,，hello
        System.out.println(PinyinHelper.toHanYuPinyinString("我是中国人，hello", format, ",", true));
        System.out.println(PinyinHelper.toHanYuPinyinString("Adidas", format, "", true));
        System.out.println(PinyinHelper.toHanYuPinyinString("雅诗兰黛 Adidas 我是中国人#$%%", format, "", true));
        System.out.println(PinyinHelper.toHanYuPinyinString("雅诗兰黛 我是中国人#$%%", format, "", false));
        System.out.println(PinyinHelper.toHanYuPinyinString("雅诗兰 黛 我 是中国人%%", format, "", true));
    }
}
